﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MoroMoro.Samples.ToDoList.Base.Application;
using MoroMoro.Samples.ToDoList.Application;
using MoroMoro.Samples.ToDoList.Application.Categories;
using MoroMoro.Samples.ToDoList.Domain.Categories;
using MoroMoro.Samples.ToDoList.Presentation.Views.Categories;
using MoroMoro.Samples.ToDoList.Presentation.ErrorMessages.Categories;

namespace MoroMoro.Samples.ToDoList.Presentation.Presenters.Categories
{
    /// <summary>
    /// カテゴリ作成プレゼンターです。
    /// </summary>
    public sealed class CategoryCreationPresenter : CategoryBuildPresenter<ICategoryCreationView, CategoryCreationErrors>
    {
        /// <summary>
        /// <see cref="CategoryCreationPresenter"/> クラスの新しいインスタンスを初期化します。
        /// </summary>
        /// <param name="view">ビュー。</param>
        /// <param name="facade">ファサード。</param>
        /// <exception cref="System.ArgumentNullException">view または facade が null です。</exception>
        public CategoryCreationPresenter(ICategoryCreationView view, ToDoListFacade facade)
            : base(view, facade, facade.CreateCategoryBuilder())
        {
        }


        /// <inheritdoc/>
        protected override void ExecuteBuild(Action<CategoryCreationErrors> errorHandler)
        {
            Facade.ExecuteCategoryCreation(Builder, errorHandler);
        }

        /// <inheritdoc/>
        protected override string CreateErrorMessage(CategoryCreationErrors error)
        {
            var errorMessage = new CategoryCreationErrorMessage();
            error.HandledBy(errorMessage);
            return errorMessage.ToString();
        }
    }
}
